<template>
  <div class="home">
    <div><img src="../assets/nav.jpg" alt="导航图片" width="100%" /></div>
    <div class="Home_list1">
      <ul>
        <li v-for="item in Home_list1" :key="item">
          <a>{{ item }}</a>
        </li>
      </ul>
    </div>
    <div class="head">
      <div class="head_start">
        <img src="../assets/logo1.png" alt="网站logo" />
      </div>
      <div class="head_center">
        <div>
          <input type="text" placeholder="限时优惠" />
          <button>搜索</button>
        </div>
        <div class="Home_list2">
          <ul>
            <li v-for="(item, index) in Home_list2" :key="`${item}-${index}`">
              <a>{{ item }}</a>
            </li>
          </ul>
        </div>
      </div>
      <div class="head_end">
        <button class="head-btn">登录</button>
        <button class="head-btn" @click="goToCart"> 
          <img src="../assets/gwc.png" alt="购物车图标" />
        </button>
      </div>
    </div>
    <div class="nav">
      <div class="nav_item">
        <div class="nav_start">
          <p class="nav-title">
            <img src="../assets/navlogo.png" alt="分类图标" />所有商品分类
          </p>
          <Classify class="Classify"></Classify>
        </div>
        <div class="Home_list3">
          <ul>
            <li
              v-for="(item, index) in Home_list3"
              :key="index"
              :class="{
                'default-active': index === 0,
                'hover-active': hoverIndex === index && index !== 0,
              }"
              @mouseenter="hoverIndex = index"
              @mouseleave="hoverIndex = -1"
            >
              <a>{{ item }}</a>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <div class="swiper-container">
      <Myswiper></Myswiper>
    </div>
    <Recommend id="recommend" />
    <Bestchart id="bestchart" />
    <Buygoods id="buygoods" />
    <Digital id="digital" />
    <Life id="life" />
    <Eat id="eat" />
    <Season id="season" />
    <RightNavigation :nav-items="navItems" />
    <End></End>
    <MyFoot></MyFoot>
  </div>
</template>

<script >
import Myswiper from "../components/vue-awesome-swiper/swiper.vue";
import MyFoot from "@/components/home/foot.vue";
import Recommend from "@/components/home/recommend.vue";
import Bestchart from "@/components/home/bestchart.vue";
import Buygoods from "@/components/home/buygoods.vue";
import Digital from "@/components/home/digital.vue";
import Life from "@/components/home/life.vue";
import Eat from "@/components/home/eat.vue";
import Season from "@/components/home/season.vue";
import End from "@/components/home/end.vue";
import Classify from "@/components/home/classify.vue";
import RightNavigation from "@/components/home/RightNavigation.vue";
export default {
  name: "HomeView",
  components: {
    Myswiper,
    MyFoot,
    Recommend,
    Bestchart,
    Buygoods,
    Digital,
    Life,
    Eat,
    Season,
    End,
    Classify,
    RightNavigation,
  },
  data() {
    return {
      Home_list1: [
        "顺电招聘",
        "我的顺电",
        "家电医院",
        "为您服务",
        "更多精选",
        "手机顺电",
        "品牌入驻",
        "仓库招租",
      ],
      Home_list2: [
        "限时专享",
        "|",
        "戴森",
        "|",
        "松下冰箱",
        "|",
        "扫地机",
        "|",
        "手机",
        "|",
        "相机特惠",
        "|",
        "Apple",
        "|",
        "游戏本",
        "|",
        "美容仪",
        "|",
        "音箱",
      ],
      Home_list3: [
        "首页",
        "Apple授权店",
        "戴森专区",
        "新品",
        "样品出清",
        "每周特惠",
        "手机专区",
        "厨电专区",
        "卡萨帝专区",
        "摄影专区",
        "电脑专区",
      ],
      hoverIndex: -1,
      activeIndex: null,
      navItems: [
        { name: "新品推荐", id: "recommend" },
        { name: "热销榜单", id: "bestchart" },
        { name: "必买好物", id: "buygoods" },
        { name: "潮人数码", id: "digital" },
        { name: "生活美家", id: "life" },
        { name: "一日三餐", id: "eat" },
        { name: "春夏秋冬", id: "season" },
      ],
    };
  },
  methods: {
    handleMouseEnter(index) {
      this.activeIndex = index;
    },
    handleMouseLeave() {
      this.activeIndex = null;
    },
       goToCart() {
      this.$router.push('/shopping-car'); 
    }
  },
};
</script>
<style>
* {
  margin: 0;
  padding: 0;
}
.home {
  width: 100%;
  height: auto;
  background-color: #f3f3f3;
}
.Home_list1 {
  width: 100%;
  margin-top: 0;
  background-color: #f5f5f5;
}
.Home_list1 ul {
  min-height: 30px;
  display: flex;
  flex-direction: row;
  float: right;
  margin-right: 700px;
}
.Home_list1::after {
  content: "";
  display: table;
  clear: both;
}
.Home_list1 ul li {
  list-style: none;
  padding: 10px 10px 0px 10px;
  font-size: 13px;
  line-height: 1;
  vertical-align: top;
}
.head {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 120px;
  justify-content: center;
  align-items: center;
}
.head_start {
  margin-right: 50px;
}
.head_center {
  flex: 1;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.head_center > div:first-child {
  width: 100%;
  display: flex;
}

.head_center input[type="text"] {
  flex: 1;
  height: 35px;
  padding: 0 15px;
  border: 1px solid #0099a8;
  outline: none;
}

.head_center button {
  width: 80px;
  height: 37px;
  background: #0099a8;
  color: white;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
}

.Home_list2 {
  width: 100%;
  margin-top: 0;
}
.Home_list2 ul {
  min-height: 30px;
  display: flex;
  flex-direction: row;
  margin-right: 200px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.Home_list2 ul li {
  list-style: none;
  padding: 5px 7px;
  font-size: 16px;
  line-height: 1;
  color: black;
  display: inline-block;
  white-space: nowrap;
  flex-shrink: 0;
}
.head_end {
  margin-left: 100px;
  display: flex;
  align-items: center;
  gap: 15px;
}

.head-btn {
  width: 50px;
  height: 40px;
  padding: 0;
  cursor: pointer;
  display: flex;
  background-color: white;
  align-items: center;
  justify-content: center;
}

.head-btn img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.nav {
  display: flex;
  background-color: #33353d;
  justify-content: center;
  height: 50px;
  align-items: stretch;
}
.nav_start {
  margin: 0 50px 0 0;
  height: 100%;
  display: flex;
  align-items: center;
  position: relative;
}
.Home_list3 {
  width: 100%;
  margin-top: 0;
}
.Home_list3 ul {
  display: flex;
  height: 100%;
  align-items: center;
  margin: 0;
  padding: 0;
}
.Home_list3 ul li {
  list-style: none;
  padding: 0 15px;
  height: 100%;
  display: flex;
  align-items: center;
  font-size: 16px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
}
.Home_list3 ul li.default-active {
  background-color: #0099a8;
}

.Home_list3 ul li.hover-active {
  background-color: #0099a8;
}

.Home_list3 ul li.default-active:hover {
  background-color: #007a8a;
}

.nav_item {
  display: flex;
  height: 100%;
  width: 100%;
  max-width: 1200px;
}
.nav-title {
  color: white;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0;
  white-space: nowrap;
}
.nav-title img {
  width: 20px;
  height: 20px;
  vertical-align: middle;
}
.Classify {
  position: absolute;
  top: 50px;
  left: -28px;
  z-index: 2;
}
.swiper-container {
  height: 520px;
  margin: 0 auto;
  width: 100%;
}
</style>
